# -*- coding: utf-8 -*-

"""
@author: Laowang
@contact: QQ:1125564921
@Created on: 2022/7/6
@Remark: 
"""
import os
import pickle
import threading
import time
from .base import *

from framework_strategy.gopy.trader.engine import EventEngine, MainEngine, StrategyTemplate


# api相关的操作
class ExampleSVCAPIMixins:

    __slots__ = ()

    def get_trade(self):
        pass

    def get_ticker(self):
        pass

    def get_depth(self):
        pass

    def get_order(self):
        pass

    def send_order(self):
        pass


class ExampleSVCStrategy(StrategyTemplate):

    # 配置信息
    DEFAULT_SETTING = {
        "model": os.path.join(os.path.dirname(__file__), "model/svc_trade.pkl"),
        "XT": (XT_PUBLIC_KEY, XT_SECRET_KEY),
    }
    APP_NAME = APP_NAME

    def __init__(self, main_engine: MainEngine, event_engine: EventEngine, *, app_name: str = APP_NAME) -> None:
        super().__init__(main_engine, event_engine, app_name)

        self.app_name = app_name or self.APP_NAME
        with open(self.DEFAULT_SETTING['model'], "rb") as f:
            self._model = pickle.load(f)

        assert self._model is not None
        self._active = False
        self.__thread = threading.Thread(
            target=self.process, name=self.__class__.__name__, daemon=True)

    def predict(self):
        pass

    def process(self):
        while self._active:
            # print("[*]  ExampleSVCStrategy is running... ")
            time.sleep(1)
        print("[ExampleSVCStrategy] exit")

    def start(self):
        self._active = True
        self.__thread.start()
        print("[ExampleSVCStrategy] starting")

    def close(self):
        self._active = False
        self.__thread.join()
        print("[ExampleSVCStrategy] stopping")

